﻿#include "CDevHy.h"
#include "CSqlOper.h"
CDevHy::CDevHy(QString sDevGuid)
{
	m_sDevGuid = sDevGuid;
	init();
}

CDevHy::CDevHy(CDevDataBase* pDevData)
{
	m_pDevDataBase = pDevData;
	m_sDevGuid = m_pDevDataBase->m_sDevGuid;
	addDev();
}

CDevHy::~CDevHy()
{
	if (m_pCamerCtrMange)
	{
		delete m_pCamerCtrMange;
		m_pCamerCtrMange = nullptr;
	}
	if (m_pRobCtrMange)
	{
		delete m_pRobCtrMange;
		m_pRobCtrMange = nullptr;
	}
}

bool CDevHy::ctrDev(SCtrInfo & stCtrInfo)
{
	//设备本体
	if (stCtrInfo.m_nCtrDevType == enOntology)
	{
		return m_pRobCtrMange->ctrDevice(stCtrInfo);
	}
	//云台
	else if (stCtrInfo.m_nCtrDevType == enSubDev1)
	{
		return m_pCamerCtrMange->ctrDevice(stCtrInfo);
	}
	return true;
}

void CDevHy::init()
{
	QString sErr = "";
	m_pDevDataBase = new CDevDataBase();
	m_pDevDataBase->m_sDevGuid = m_sDevGuid;
	selRobHostById(m_pDevDataBase, sErr);
	selRobPanTiltById(m_pDevDataBase, sErr);
	selectRobSensorByID(m_pDevDataBase, sErr);
	selectIoByID(m_pDevDataBase, sErr);
	selectRobRollerNoConfigByID(m_pDevDataBase, sErr);
	m_pRobCtrMange = new CRobCtrMange(m_pDevDataBase);   //创建设备操作管理类对象
	m_pRobCtrMange->threadRun();
	m_pCamerCtrMange = new CCamerCtrMange(m_pDevDataBase);
}
void CDevHy::addDev()
{
	QString sErr = "";
	m_sDevGuid = m_pDevDataBase->m_sDevGuid;
	m_pRobCtrMange = new CRobCtrMange(m_pDevDataBase);   //创建设备操作管理类对象
	selRobPanTiltById(m_pDevDataBase, sErr);
	selectRobSensorByID(m_pDevDataBase, sErr);
	selectIoByID(m_pDevDataBase, sErr);
	m_pRobCtrMange->threadRun();
	m_pCamerCtrMange = new CCamerCtrMange(m_pDevDataBase);
}

